package com.swind.fast.modules.app.halali.customer.service.impl;

import com.swind.fast.common.util.oConvertUtils;
import com.swind.fast.common.api.HalaliCommonAPI;
import com.swind.fast.common.constant.CacheConstant;
import org.springframework.cache.annotation.Cacheable;
import com.swind.fast.common.system.vo.HalaliLoginUser;
import org.springframework.beans.BeanUtils;

import com.swind.fast.modules.app.halali.customer.entity.UserFavorite;
import com.swind.fast.modules.app.halali.customer.mapper.UserFavoriteMapper;

import com.swind.fast.modules.app.halali.customer.entity.HalaliUser;
import com.swind.fast.modules.app.halali.customer.service.IHalaliUserService;
import com.swind.fast.modules.app.halali.customer.entity.HalaliPartner;
import com.swind.fast.modules.app.halali.customer.service.IHalaliPartnerService;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.ApplicationContext;

import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.date.DateBetween;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;

import javax.annotation.Resource;

import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;

/**
 * @Description: 项目
 * @Author: swind
 * @Date:   2021-11-20
 * @Version: V1.0
 */
@Slf4j
@Service
public class HalaliBaseApiImpl implements HalaliCommonAPI {

    @Autowired
    private IHalaliUserService halaliUserService;

    @Autowired
    private IHalaliPartnerService halaliPartnerService;

    @Override
    @Cacheable(cacheNames = CacheConstant.SYS_USERS_CACHE, key = "#mobile")
    public HalaliLoginUser getUserByMobile(String mobile) {
        if(oConvertUtils.isEmpty(mobile)) {
            return null;
        }
        HalaliLoginUser loginUser = new HalaliLoginUser();

        HalaliUser halaliUser = halaliUserService.getUserByMobile(mobile);
        if (halaliUser == null) {
            return null;
        }
        BeanUtils.copyProperties(halaliUser, loginUser);
        return loginUser;
    }

    @Override
    @Cacheable(cacheNames = CacheConstant.SYS_USERS_CACHE, key = "#email")
    public HalaliLoginUser getUserByEmail(String email) {
        if(oConvertUtils.isEmpty(email)) {
            return null;
        }
        HalaliLoginUser loginUser = new HalaliLoginUser();

        HalaliPartner halaliUser = halaliPartnerService.getUserByEmail(email);
        if (halaliUser == null) {
            return null;
        }
        BeanUtils.copyProperties(halaliUser, loginUser);
        return loginUser;
    }
}
